const superagent = require('superagent');
const cheerio = require('cheerio');
const config = require('./config');
let $ = null;
const getLoginData = () => {
  return new Promise((res, rej) => {
    superagent.get(config.login).end((err, data) => {
      if (err) {
        rej(err);
        return;
      }
      const cookie = data.headers['set-cookie'];
      $ = cheerio.load(data.text);
      let __VIEWSTATE = $('#__VIEWSTATE').attr('value');
      let __VIEWSTATEGENERATOR = $('#__VIEWSTATEGENERATOR').attr('value');
      res({ __VIEWSTATE, __VIEWSTATEGENERATOR, cookie });
    });
  });
};

module.exports = getLoginData;
